package com.umeox.watch.moto.settings.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.core.content.res.getDrawableOrThrow
import com.umeox.moto.watch.themes.widget.ImageView
import com.umeox.moto.watch.themes.widget.TextView
import com.umeox.watch.moto.settings.R

/**
 * Created by Rambo 2024/4/29/0029
 * Describe:
 */
class SettingsItem @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
): LinearLayout(context, attrs, defStyleAttr) {

    private var ivIcon: ImageView
    private var tvTitle: TextView

    init {
        val view =
            LayoutInflater.from(context).inflate(R.layout.settings_item, this)

        ivIcon = view.findViewById(R.id.icon_iv)
        tvTitle = view.findViewById(R.id.title_tv)

        val a = context.obtainStyledAttributes(attrs, R.styleable.SettingsItem, defStyleAttr, 0);
        val iconDrawable = a.getDrawable(R.styleable.SettingsItem_u_icon)
        val title = a.getString(R.styleable.SettingsItem_u_title)
        ivIcon.setImageDrawable(iconDrawable)
        tvTitle.text = title
        a.recycle()
    }

}